// https://www.luogu.com.cn/problem/P1213
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
using ll = long long;
using T = int;
T rad(); // quick read
const int inf = 0x3f3f3f3f;
#define rf(i, n) for (int i = 1; i <= (n); ++i)
#define rep(i, s, t, d) for (int i = (s); i <= (t); i += d)
const int max_size = 5 + 100;
const int maxn = 5 + 1e6;

/*
 0
3 1
 2
*/
// mv[i][j] 第 i + 1 种方法，第 j 个格子的改变量
int mv[9][9] = {{1, 1, 0, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 0, 1, 1, 0, 0, 0}, {1, 0, 0, 1, 0, 0, 1, 0, 0}, {0, 1, 0, 1, 1, 1, 0, 1, 0}, {0, 0, 1, 0, 0, 1, 0, 0, 1}, {0, 0, 0, 1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0, 1, 1}};

int a[9];

int maxd; // max dep
int cnt[9];
int top, path[maxn];
void dfs(int dep, int last) {
    if (dep >= maxd) { // 迭代加深剪枝
        for (int i = 0; i < 9; ++i)
            if (a[i] != 0) return;
        throw 1;
    };
    for (int i = last; i < 9; ++i) { // 重复性剪枝
        if (cnt[i] == 3) continue;   // 最优性剪枝
        rep(j, 0, 9, 1) a[j] = (a[j] + mv[i][j]) % 4;
        path[top++] = i + 1, cnt[i]++;
        dfs(dep + 1, i);
        top--, cnt[i]--;
        rep(j, 0, 9, 1) a[j] = (a[j] + 4 - mv[i][j]) % 4;
    }
}

int main() {
    for (int i = 0; i < 9; ++i) {
        a[i] = rad() / 3 % 4;
    }
    try {
        int ed = 1e3;
        while (++maxd < ed)
            dfs(0, 0);
    } catch (int) {
        for (int i = 0; i < top; ++i)
            printf("%d ", path[i]);
    }
}

T rad() {
    T back = 0;
    int ch = 0, posi = 0;
    for (; ch < '0' || ch > '9'; ch = getchar())
        posi = ch ^ '-';
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        back = (back << 1) + (back << 3) + (ch & 0xf);
    return posi ? back : -back;
}